package com.agent;

import com.interceptor.TimingInterceptor;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;

import java.lang.instrument.Instrumentation;

public class T_02_TimingInterceptorAgent {
    /**
     * 将所有加载 的类全部打印出来
     * @param inst
     */
    public static void premain(String args, Instrumentation inst) {
        new AgentBuilder.Default()
                .type(ElementMatchers.nameStartsWith("com.test")) // 只改业务包
                .transform((builder, td, cl, m) ->
                        builder.method(ElementMatchers.any())
                                .intercept(MethodDelegation.to(TimingInterceptor.class))
                ).installOn(inst);
    }
}